package com.hry.store.service.impl;

import com.hry.store.dao.ShippingMapper;
import com.hry.store.pojo.Shipping;
import com.hry.store.service.ShippingService;
import com.hry.store.vo.ShippingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShippingServiceImpl implements ShippingService {

    @Autowired
    private ShippingMapper shippingMapper;

    /**
     * 更新收货地址
     * @param shipping
     * @return
     */
    @Override
    public int updateShipping(Shipping shipping) {
        return shippingMapper.updateByPrimaryKeySelective(shipping);
    }

    /**
     * 根据email 查询收货地址
     * @param userEmail
     * @return
     */
    @Override
    public List<Shipping> findShippingByEmail(String userEmail) {

        return shippingMapper.findShippingByEmail(userEmail);
    }

    /**
     * 新增收货地址
     */
    @Override
    public int addNewAddress(String userEmail, String receiverName, Long receiverPhone, Integer receiverProvince, Integer receiverCity, String receiverAddress, Integer receiverDistract) {
        Shipping shipping = new Shipping();
        shipping.setReceiverName(receiverName);
        shipping.setReceiverPhone(receiverPhone);
        shipping.setReceiverAddress(receiverAddress);
        shipping.setReveiverDistract(receiverDistract);
        shipping.setReceiverProvince(receiverProvince);
        shipping.setReceiverCity(receiverCity);
        shipping.setUserEmail(userEmail);
        return shippingMapper.insertSelective(shipping);
    }

    /**
     * 根据shippingId查询详细信息
     * @param shippingId
     * @return
     */
    @Override
    public Shipping getDetailByShippingId(Integer shippingId) {
        return shippingMapper.selectByPrimaryKey(shippingId);
    }

    /**
     * 删除收货地址
     * @param shippingId
     * @return
     */
    @Override
    public int deleteByShippingId(Integer shippingId) {
        return shippingMapper.deleteByPrimaryKey(shippingId);
    }


}
